package com.example.syssoft.controller;

import com.example.syssoft.common.controller.LogicController;
import com.example.syssoft.config.Result;
import com.example.syssoft.dao.CustomerDao;
import com.example.syssoft.domain.Customer;
import com.example.syssoft.domain.param.AddOrderParam;
import com.example.syssoft.service.CustomerService;
import com.example.syssoft.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Tag(name = "顾客控制器")
@RequestMapping("/customer")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer,Long> {

    @Resource
    OrderService orderService;

    public CustomerController(CustomerService ls) {
        super(ls);
    }

    @GetMapping("/getOrder")
    @Operation(summary = "获得订单")
    public Result getOrder(Long customerId,Long shopId){
        return getService().getOrder(customerId,shopId);
    }

    @PostMapping("/addOrder")
    @Operation(summary = "新增订单")
    public Result addOrder(@RequestBody  AddOrderParam param){
        return getService().addOrder(param.getCustomerId(),param.getShopId(),param.getTotalPrice(),param.getList());
    }

    @GetMapping("/pay")
    @Operation(summary = "支付订单")
    public Result payOrder(Long orderId){
        return getService().payState(orderId);
    }

    @GetMapping("/deleteOrder")
    @Operation(summary = "删除订单")
    public Result deleteOrder(Long orderId){
        orderService.DELETE(orderId);
        return new Result(true,"删除成功");
    }

    @GetMapping("/getAllOrder")
    @Operation(summary = "获取所有订单")
    public Result getAllOrder(Long customerId){
        return getService().getAllOrder(customerId);
    }

    @GetMapping("/getFinshOrder")
    @Operation(summary = "获取已支付订单")
    public Result getFinshOrder(Long customerId){
        return getService().getOrderByPayState(customerId,1);
    }

    @GetMapping("/getNoFinshOrder")
    @Operation(summary = "获取未支付订单")
    public Result getNoFinshOrder(Long customerId){
        return getService().getOrderByPayState(customerId,0);
    }

    @GetMapping("/getRefuseOrder")
    @Operation(summary = "获取退款订单")
    public Result getRefuseOrder(Long customerId){
        return getService().getOrderByState(customerId,2,1);
    }

    @GetMapping("/getOrderById")
    @Operation(summary = "根据orderid查询订单")
    public Result getOrderById(Long orderId){
        return getService().getOrderById(orderId);
    }
}
